package biz;

import dao.PhoneManageDao;

public class PhoneBiz {
    private PhoneManageDao dao = new PhoneManageDao();

    public void check(String product, String price, String count, String type, String image, String color) throws BizException {

        if (product.length() < 2 || product.length() > 30){
            throw new BizException("产品名必须是2~30个字符");
        }
        if (price == null || price.trim().isEmpty()){
            throw new BizException("请输入产品价格");
        }
        if (count == null || count.trim().isEmpty()){
            throw new BizException("请输入产品数量");
        }
        if (type == null || type.trim().isEmpty()){
            throw new BizException("请输入产品类型");
        }
        if (image == null || image.trim().isEmpty() || image.length() == 0){
            throw new BizException("请上传图片");
        }
        if (color.length() < 2 || color.length() > 6){
            throw new BizException("产品颜色要求2~6个字符");
        }
    }

    public void create(String product, String price, String count, String type,String intro, String image, String color) throws BizException {
        check( product, price, count, type, image, color);
        if (dao.exists(product) == 1){
            // 如果存在 则不允许添加
            throw new BizException("该商品已存在!");
        }
        dao.create(product, price, count, type, intro, image, color);
    }

    public void modify(String id, String product, String price, String count, String type,String intro, String image, String color) throws BizException {
        check( product, price, count,type, image, color);
        dao.modify(id, product, price, count, type, intro, image, color);
    }

    public void remove(String id){
        dao.remove(id);
    }
    public void remove1(String id){
        dao.remove1(id);
    }
}
